﻿using System;
using System.Linq;
using System.IO;

namespace ReadFiles
{
    class ReadFiles
    {
        static void Main()
        {
            /* 3. Write a program that enters file name along with its full file path (e.g. C:\WINDOWS\win.ini), 
             *    reads its contents and prints it on the console. Find in MSDN how to use System.IO.File.ReadAllText(…). 
             *    Be sure to catch all possible exceptions and print user-friendly error messages.
             */

            Console.WriteLine("Enter full file path:");
            string fileName = Console.ReadLine(); // @"..\..\ReadFiles.cs";
            string strRead;
            try
            {
                StreamReader reader = new StreamReader(fileName);
                Console.WriteLine("File {0} successfully open.", fileName);
                Console.WriteLine("File contents:");
                using (reader)
                {
                    strRead = File.ReadAllText(fileName);
                }
                Console.WriteLine(strRead);
            }
            catch (FileNotFoundException)
            {
                Console.Error.WriteLine("Can not find file {0}.", fileName);
            }
            catch (DirectoryNotFoundException)
            {
                Console.Error.WriteLine("Invalid directory in the file path.");
            }
            catch (IOException)
            {
                Console.Error.WriteLine("Can not open the file {0} due to I/O error.", fileName);
            }
        }         
    }
}
